﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VAdvantage.Classes;
using VAdvantage.Grids;
using VAdvantage.Utility;

namespace VAdvantage.Model
{
    public class CalloutModuleMgmt : CalloutEngine
    {
        public String GenerateMenuItemExportID(Context ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
        {


            if (IsCalloutActive()) // assuming it is resetting value
            {
                return "";
            }
            string modulePrefix = ctx.GetContext(WindowNo, "Prefix");

            
            if ((mTab.GetValue("MenuItemExport_ID") == null && mTab.GetValue("IsMenuItem").ToString()=="True"))
            {
                string ExportID = modulePrefix + DateTime.UtcNow.Ticks;
                mTab.SetValue("MenuItemExport_ID", ExportID);
            }
            
            SetCalloutActive(false);
            return "";
        }

        public String GenerateVersionID(Context ctx, int WindowNo, GridTab mTab, GridField mField, Object value)
        {


            if (IsCalloutActive()) // assuming it is resetting value
            {
                return "";
            }
            string versionno = ctx.GetContext(WindowNo, "VersionNo");
            string versionid=versionno.Replace(".","");
            mTab.SetValue("VersionID", versionid);

            //if ((mTab.GetValue("MenuItemExport_ID") == null && mTab.GetValue("IsMenuItem").ToString() == "True"))
            //{
            //    string ExportID = modulePrefix + DateTime.UtcNow.Ticks;
            //    mTab.SetValue("MenuItemExport_ID", ExportID);
            //}

            SetCalloutActive(false);
            return "";
        }

        public string CheckBoxValidation(Context ctx, int windowNo, GridTab mTab, GridField mField, Object value)
        {
            if (IsCalloutActive()) // assuming it is resetting value
            {
                return "";
            }
            if (value == DBNull.Value || value == null || value.ToString() == "")
            {
                return "";
            }
            bool CheckBoxValue = Util.GetValueOfBool(value);
            if (CheckBoxValue == true)
            {
                string columnName = mField.GetColumnName();
                if (columnName == "IsProfessionalFree")
                {
                    mTab.SetValue("IsProfessionalPaid", false);
                    mTab.SetValue("IsFree", false);
                    mTab.SetValue("IsPaid", false);
                    // mTab.SetValue("IsProfessionalPaid", false);
                }
                else if (columnName == "IsProfessionalPaid")
                {
                    mTab.SetValue("IsProfessionalFree", false);
                    mTab.SetValue("IsFree", false);
                    mTab.SetValue("IsPaid", false);
                }
                else if (columnName == "IsFree")
                {
                    mTab.SetValue("IsProfessionalPaid", false);
                    mTab.SetValue("IsProfessionalFree", false);
                    mTab.SetValue("IsPaid", false);
                }
                else if (columnName == "IsPaid")
                {
                    mTab.SetValue("IsProfessionalPaid", false);
                    mTab.SetValue("IsFree", false);
                    mTab.SetValue("IsProfessionalFree", false);
                }
            }

            SetCalloutActive(false);
            return "";
        }
    }
}
